import { UsersEntity } from 'src/module/user/entities/user.entity';
import {
  BeforeInsert,
  BeforeUpdate,
  Column,
  Entity,
  JoinColumn,
  OneToOne,
  PrimaryColumn,
} from 'typeorm';
import { v4 as uuidv4 } from 'uuid';
import * as moment from 'moment';

@Entity({ name: 'account' })
export class AccountEntity {
  @PrimaryColumn()
  id: string = uuidv4();

  @Column({ type: 'varchar', length: 30 })
  accountnumer: string;

  @OneToOne(() => UsersEntity, (user) => user.account)
  user: UsersEntity;

  @Column({ type: 'varchar', nullable: true })
  created_at: string;

  @Column({ type: 'varchar', nullable: true })
  updated_at: string;

  @BeforeInsert()
  createDates() {
    this.created_at = moment().format('YYYY-MM-DD HH:mm:ss');
  }

  @BeforeUpdate()
  updateDates() {
    this.updated_at = moment().format('YYYY-MM-DD HH:mm:ss');
  }
}
